home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
fax.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
183 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* fax -
* Support for writing fax files
*
* Paul Haeberli - 1989
*/
#include "stdio.h"
#include "fax.h"
static puteol();
static flushbits();
static putwhitespan();
static putblackspan();
static putcode();
static int putbit();
/*
* generic fax stuff follows
*
*/
static FILE *faxf;
static int shdata;
static int shbit = 0x01;
openfax(name)
char *name;
{
faxf = fopen(name,"w");
if(!faxf) {
fprintf(stderr,"openfax: can't open output file %s\n",name);
exit(1);
}
}
closefax()
{
int i;
for(i=0; i<10; i++)
puteol();
flushbits(faxf);
fclose(faxf);
}
tofax(sbuf,n)
short *sbuf;
int n;
{
int c = 0;
puteol();
while(n>0) {
c = 0;
while(*sbuf>128 && n>0) {
sbuf++;
c++;
n--;
}
putwhitespan(c);
c = 0;
if(n==0)
break;
while(*sbuf<=128 && n>0) {
sbuf++;
c++;
n--;
}
if(n>0 && c>0)
putblackspan(c);
}
}
static putwhitespan(c)
int c;
{
int tpos;
tableentry *te;
if(c>=64) {
tpos = (c/64)-1;
te = mwtable+tpos;
c -= te->count;
putcode(te);
}
tpos = c;
te = twtable+tpos;
putcode(te);
}
static putblackspan(c)
int c;
{
int tpos;
tableentry *te;
if(c>=64) {
tpos = (c/64)-1;
te = mbtable+tpos;
c -= te->count;
putcode(te);
}
tpos = c;
te = tbtable+tpos;
putcode(te);
}
static putcode(te)
tableentry *te;
{
unsigned int mask;
int code;
mask = 1<<(te->length-1);
code = te->code;
while(mask) {
if(code&mask)
putbit(1);
else
putbit(0);
mask >>= 1;
}
}
static puteol()
{
int i;
for(i=0; i<11; i++)
putbit(0);
putbit(1);
}
static putzeros()
{
int i;
for(i=0; i<64; i++)
putbit(0);
}
static int putbit(d)
int d;
{
int i;
int b;
if(d)
shdata = shdata|shbit;
shbit = shbit<<1;
if((shbit&0xff) ==0) {
putc(shdata,faxf);
shdata = 0;
shbit = 0x01;
}
}
static flushbits()
{
if(shbit!=0x80) {
putc(shdata,faxf);
shdata = 0;
shbit = 0x01;
}
}